export default function (type,need){
	let d = new Date(),
		e_year = d.getFullYear(),
		e_month = d.getMonth() + 1,
		e_day = d.getDate(),
		e_w_d = d.getDay(),
		e_hour = d.getHours(),
		e_minutes = d.getMinutes(),
		e_seconds = d.getSeconds(),
		e_str
	e_month = revise(e_month)
	e_hour = revise(e_hour)
	e_minutes = revise(e_minutes)
  e_seconds = revise(e_seconds)
	e_day = revise(e_day)
	// e_str = e_year + "-" + e_month + "-" + e_day + " " + e_hour + ":" + e_minutes + ":00"
	e_str = e_year + "-" + e_month + "-" + e_day
  if(need&&need === "monitorTime"){
    return {
      year: e_year,
      month: e_month,
      day: e_day,
      hour: e_hour,
      minute: e_minutes,
      seconds: e_seconds
    }
  }
	switch(type){
		//今天是截至到目前
		case "today":
		return {
			start: e_year + "-" + e_month + "-" + e_day,
			end: e_str
		}
		break
		//昨天0点至今天0点是昨天一天
		case "yesterday":
		let l_d = new Date(+new Date() - 24*60*60*1000)
		return {
			start: l_d.getFullYear() + "-" + (revise(l_d.getMonth() + 1)) + "-" + l_d.getDate(),
			end:  l_d.getFullYear() + "-" + (revise(l_d.getMonth() + 1)) + "-" + l_d.getDate(),
		}
		break
    //近三天
    case "threeDays":
      let s_d = new Date(+new Date() - 3*24*60*60*1000)
      return {
        start: s_d.getFullYear() + "-" + (revise(s_d.getMonth() + 1)) + "-" + s_d.getDate()+ " " + (revise(s_d.getHours())) + ":" + (revise(s_d.getMinutes())) + ":" + (revise(s_d.getSeconds())),
        end: e_str + " " + e_hour + ":" + e_minutes + ":" + e_seconds
      }
		//本周一0点至今
		case "week":
		let n,
			l_w
		if(e_w_d == 0){
			n = 6
		}else{
			n = e_w_d - 1
		}
		l_w = new Date(new Date().getTime() - n*24*60*60*1000)
		return {
			start: l_w.getFullYear() + "-" + (revise(l_w.getMonth() + 1)) + "-" + l_w.getDate(),
			end:  e_str,
		}
		break
    case "lastWeek":
      let n1,
        l_w1,
        l_w2
      if(e_w_d == 0){
        n = 6
      }else{
        n = e_w_d - 1
      }
      l_w1 = new Date(new Date().getTime() - n*24*60*60*1000 - 7*24*60*60*1000)
      l_w2 = new Date(new Date().getTime() - n*24*60*60*1000 - 1*24*60*60*1000)
      return {
        start: l_w1.getFullYear() + "-" + (revise(l_w1.getMonth() + 1)) + "-" + l_w1.getDate(),
        end: l_w2.getFullYear() + "-" + (revise(l_w2.getMonth() + 1)) + "-" + l_w2.getDate()
      }
		case "month":
		return {
			start: e_year + "-" + e_month + "-" + "01",
			end:  e_str,
		}
		case "year":
		if(e_month < 7){
			return {
				start: e_year + "-" + "01" + "-" + "01" + " " + "00:00:00",
				end:  e_str,
			}
		}else{
			return {
				start: e_year + "-" + "07" + "-" + "01" + " " + "00:00:00",
				end:  e_str,
			}
		}
		break
	}
}
function revise(m){
	if(m < 10){
		for(let i = 0;i < 10;i++){
			if(m == i){
				let p = "0" + i
				return p
			}
		}
	}else{
		return m
	}
}
